package org.casaca.checkbackup.core.data;

import java.math.BigInteger;

import org.casaca.checkbackup.core.checksum.ChecksumGroup;


public class File extends SystemElement {
	
	private BigInteger size;
	private String extension;
	private ChecksumGroup checksumGroup;
	
	public File(Folder parent, String name) {
		super(parent, name);
		
		java.io.File f = new java.io.File(parent.getPath()+System.getProperty("file.separator")+name);
		this.size = (f.exists())?BigInteger.valueOf(f.length()):BigInteger.ZERO;
		this.extension = (name.lastIndexOf(".")>0)?name.substring(name.lastIndexOf(".")):null;
		this.checksumGroup = new ChecksumGroup(this.getPath());
	}

	public String getExtension() {
		return extension;
	}

	public void setExtension(String extension) {
		this.extension = extension;
	}
	
	public ChecksumGroup getChecksumGroup() {
		return checksumGroup;
	}

	public void setChecksumGroup(ChecksumGroup checksumGroup) {
		this.checksumGroup = checksumGroup;
	}

	@Override
	public BigInteger getSize() {
		return size;
	}

	@Override
	public void setSize(BigInteger size) {
		if(size==null)
			throw new IllegalArgumentException("Size must not be null");
		
		this.size = size;
	}

	@Override
	public int compareTo(SystemElement o) {
		if(o instanceof Folder)
			return 1;
		else
			return this.getName().compareTo(o.getName());
	}
}